package com.xuan.book.mapper;

import com.xuan.book.model.BookInfo;
import com.xuan.book.model.PageRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookInfoMapper {

    @Insert("insert into book_info (book_name, author, count, price, publish) values " +
            "(#{bookName}, #{author}, #{count}, #{price}, #{publish})")
    Integer addBook(BookInfo bookInfo);

    // 查询某页数据
    @Select("select * from book_info where `status` <>0 order by id desc limit #{offset}, #{pageSize}")
    List<BookInfo> getListByPage(PageRequest pageRequest);

    // 查询图书总数
    @Select("select count(1) from book_info where status != 0")
    Integer count();

    // 根据 id 查询当前图书信息
    @Select("select * from book_info where status != 0 and id = #{id}")
    BookInfo queryBookInfoById(Integer id);

    // 根据 id 修改图书信息
    Integer updateBook(BookInfo bookInfo);

    // 根据图书 id 批量删除图书
    Integer batchDeleteBook(int[] ids);
}
